<?php

$page = 'Server Error! Plese Try Again Later';
$price = '';
if ( isset ($_GET['idCs']) ){
$id=$_GET['idCs'];
$db = new DBManager ( 'localhost', 'root', '', 'iumus' );
$query='SELECT * FROM movie WHERE id ='.'\''.$id.'\';';
$result=$db->executeQuery ($query);
$row=mysql_fetch_array($result);
//$response=$row['title'].'#'.$row['year'].'#'.$row['genre'].'#'.$row['actors'].'#'.$row['director'].'#'.$row['cover'];
if($row['cover']!='N/A')
	$pathImage=$row['cover'];
//$page="<html><head><title>".$row['title']." (".$row['year'].")</title></head>";
if($row['plot']!='N/A')
	$plot='<b>Plot : </b>'.$row['plot'];
else $plot="<b>Plot : </b> not yet released";
$page="<table border=2><tr><td>&nbsp;</td></tr>
			<tr>
				<td>
					<img src='".$pathImage."' style='max-width:214px; max-height:317px;' height='317'/>"."
				</td>
				<td style='vertical-align:top'>
					<table width=300>
						<tr>
							<td>
								<h3><b>Genre : </b>".$row['genre']."</h3>
								<h5>Runtime : ".$row['runtime']."</h5>
							</td>
						</tr>
						<tr>
							<td>".$plot."</td>
						</tr>
						<tr>
							<td>
								<h3><b>Directors :</b>".$row['director']."</h3>
								<h3><b>Actors :</b>".$row['actors']."</h3>
							</td>
						</tr>
					</table>
				</td>
			</tr>
		</table>";
}
else if ( isset ($_GET['id']) ){
$id=$_GET['id'];
$db = new DBManager ( 'localhost', 'root', '', 'iumus' );

$query='SELECT COUNT(*) AS isTvSeries FROM movie WHERE id_origin ='.'\''.$id.'\' AND id <>'.'\''.$id.'\';';
$result=$db->executeQuery ($query);
$row=mysql_fetch_array($result);
$isTvSeries = $row['isTvSeries'];
	

$query='SELECT * FROM movie WHERE id ='.'\''.$id.'\';';
$result=$db->executeQuery ($query);
$row=mysql_fetch_array($result);
if($row['cover']!='N/A')
	$pathImage=$row['cover'];
else $pathImage= "wp-content/themes/theme1273/images/noCover.png";
if($row['plot']!='N/A')
	$plot=''.$row['plot'];
else $plot="Plot not yet released";

$str4Series = '';

$username = '';
if ( isset ( $_SESSION['username'] ) ) $username = $_SESSION['username'];

if ($isTvSeries > 0){
	$str4Series = '<tr><td colspan="2"><span style="font-size:16px; " >buy the whole series or <a href="#" style="color:#FFF ">choose to watch one of '.$isTvSeries.' episodes</a></span></td></tr>';
}

if($isTvSeries == 0)
	if($row["year"] >=2010)
		$price = '2.99';
	else $price = '1.99';
else{
	$price = (0.35*$isTvSeries).'';
	if(strlen( $price ) == 3 )
		$price.='0';
	else 
		$price.='';
	$price = str_replace('.', ',',$price);
}
		

$page="<table border=2><tr><td>&nbsp;</td></tr>
			<tr>
				<td>
					<img src='".$pathImage."' style='max-width:214px; max-height:317px;' height='317'/>"."
				</td>
				<td style='vertical-align:top'>
					<table width='100%'>
						<tr>
							<td>
								<h3><span style='color:#FFF; font-weight:bold;'> Genre: </span><span style='font-size:12px; font-weight:normal;'>".$row['genre']."</span></h3>
								<h5>Runtime : ".$row['runtime']."</h5>
							</td>
						</tr>
						<tr>
							<td style='text-align:justify'>".$plot."</td>
						</tr>
						<tr>
							<td>
								<h3><span style='color:#FFF; font-weight:bold;'> Directors: </span><span style='font-size:12px; font-weight:normal;'>".$row['director']."</span></h3>
								<h3><span style='color:#FFF; font-weight:bold;'> Actors: </span><span style='font-size:12px; font-weight:normal;'>".$row['actors']."</span></h3>
							</td>
						</tr>
					</table>
				</td>
			</tr>
			<tr>
				<td colspan='2'>
				<table width='100%'>
					<tr>
						<td><a href='insertFilms.php?id=".$id."&user=".$username."&price=".$price."'><img onmouseover='bOver(this)' onmouseout='bOut(this)' src='wp-content/themes/theme1273/images/buyNow.png' /></a></td>
						<td><a href='insertWatchList.php?id=".$id."&user=".$username."'><img onmouseover='wOver(this)' onmouseout='wOut(this)' src='wp-content/themes/theme1273/images/watchlist.png' /></a></td>
					</tr>
				</table>
				</td>
			</tr>
			".$str4Series."
		</table>";

		

}


	
echo $page;



$contTitle = '<table width=\"100%\"><tr><td style=\"border:none\"><span style= \"font-size:18px; \">'.$row["title"].' ('.$row["year"].')</span></td><td style=\"text-align:right; border:none\"><span style= \"font-size:18px;  \">'.$price.' €</span></td></tr></table>';

echo '<script type="text/javascript">
	var title=document.getElementById("contentTitle");
	title.innerHTML="'.$contTitle.'";
	</script>';
?>

<script type="text/javascript" >
	function wOver(obj){
		obj.src = 'wp-content/themes/theme1273/images/watchlistOver.png'
	}
	function wOut(obj){
		obj.src = 'wp-content/themes/theme1273/images/watchlist.png'
	}
	function bOver(obj){
		obj.src = 'wp-content/themes/theme1273/images/buyNowOver.png'
	}
	function bOut(obj){
		obj.src = 'wp-content/themes/theme1273/images/buyNow.png'
	}
</script>
